#!/bin/bash
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/sys_check.sh"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/alias.sh"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/conda_and_pip_settings.sh"

conda config --set show_channel_urls yes


APP_TARGET_DIR_NAME="ace-step"

CONDA_PREFIX="./venv"

export CURRENT_APP_PATH="${LMD_APPS_DIR}/${APP_TARGET_DIR_NAME}"
echo 'App Dir: '${CURRENT_APP_PATH}

cd "$CURRENT_APP_PATH"

if [ -z "$HF_ENDPOINT" ] && [ -n "$HF_MIRROR" ]; then
    export HF_ENDPOINT="$HF_MIRROR"
fi

export GRADIO_TEMP_DIR="$CURRENT_APP_PATH/temp"

echo "use ./venv to start app."

if [ -f /System/Library/CoreServices/SystemVersion.plist ]; then
  BF16_PARAM="--bf16 false"
  TORCH_COMPILE_PARAM="--torch_compile true"
elif current_os_is_windows; then
  BF16_PARAM=""
  TORCH_COMPILE_PARAM=""
else
  echo "Unknown OS"
fi

PORT_PARAM=""
if [ -n "$GRADIO_SERVER_PORT" ]; then
  PORT_PARAM="--port $GRADIO_SERVER_PORT"
fi

conda run -p $CONDA_PREFIX --no-capture-output acestep $PORT_PARAM  --cpu_offload true --overlapped_decode true $BF16_PARAM $TORCH_COMPILE_PARAM --checkpoint_path ./checkpoints/hub


